﻿using Framework;

public enum StatusTypeEnum
{
    HP,
    Energy,
    Dizzy,
}

public class ModifyStatusEffector : BaseEventEffector
{
    public StatusTypeEnum StatusType;
    public bool ForSelf;
    public int Value;

    public override void DoEvent(ObjHandle<LogicEntity> owner, params object[] allParams)
    {
        ObjHandle<LogicEntity> target = ForSelf ? FightGame.Instance.GetMyEntity(owner.handle.PlayerID) : FightGame.Instance.GetRivalEntity(owner.handle.PlayerID);
        LogicStatusComponent statusComponent = target.handle.GetLogicComponent<LogicStatusComponent>();
        switch(StatusType)
        {
            case StatusTypeEnum.HP:
                statusComponent.HP -= Value;
                break;
            case StatusTypeEnum.Energy:
                statusComponent.Energy -= Value;
                break;
            case StatusTypeEnum.Dizzy:
                statusComponent.Dizzy -= Value;
                break;
        }
    }

    public override void OnDestroy()
    {
    }

    public override void Serialize(EByte ms)
    {
        ms.WriteInt((int)StatusType);
        ms.WriteInt(ForSelf ? 1 : 0);
        ms.WriteInt(Value);
    }

    public override void Deserialize(EByte ms)
    {
        StatusType = (StatusTypeEnum)ms.ReadInt();
        ForSelf = ms.ReadInt() == 1;
        Value = ms.ReadInt();
    }
}
